import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

class Test6 extends StatefulWidget{
    _TestState createState() => _TestState();
}

class _TestState extends State<Test6> {

    TextEditingController inputQrValue = TextEditingController();
        String qrValue = "";

    @override
    Widget build(BuildContext context) {
        return new Scaffold(
            appBar: AppBar(
                title: Text("生成二维码"),
                centerTitle: true,
            ),
            body: SingleChildScrollView(
                child: Column(
                    children: <Widget>[
                        qrValue == ""?Container(
                            height: 200.0,
                            width: 200.0,
                            alignment: Alignment.topCenter,
                            child: Center(
                                child: Text("请输入值点击下方按钮生成二维码"),
                            ),
                        ):QrImage(
                            data: qrValue,
                            size: 200.0,
                            onError: (ex) {
                                print("[QR] ERROR - $ex");
                            },
                        ),
                        Container(
                            padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
                            child: TextField(
                                controller: inputQrValue,
                                decoration: InputDecoration(
                                    labelText: "二维码值",
                                    // hintText: "请输入二维码值",
                                    prefixIcon: Icon(Icons.person)
                                ),
                            ),
                        ),
                        Container(
                            width: double.infinity,
                            height: 40.0,
                            margin: EdgeInsets.all(40.0),
                            child: FlatButton(
                                color: Color.fromRGBO(81, 126, 219, 1),
                                shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                                child: Text(
                                    "生成二维码",
                                    style: TextStyle(color: Colors.white),
                                ),
                                onPressed: (){
                                    print(inputQrValue.text);
                                    setState(() {
                                        qrValue = inputQrValue.text;
                                    });
                                },
                            )
                        ),
                    ],
                ),
            )
            
        );
    }


}
